﻿var myApp = angular.module('friendsApp', []);

//Home controller
myApp.controller('HomeController', function ($scope) {
    $scope.friendNameInput = "";
    $scope.friendFireInput = "";
    $scope.myFriendList = [];
    $scope.editMode = false;
    $scope.currIndex = -1;

    // Add a friend
    $scope.doAddTask = function () {
        $scope.myFriendList.push({ name: $scope.friendNameInput, firebase: $scope.friendFireInput });
        $scope.friendNameInput = "";
        $scope.friendFireInput = "";
    }

    //Birdie Alterator
    $scope.doEditTask = function (id) {
        var toEdit = $scope.myFriendList[id];
        $scope.friendFireInput = toEdit.firebase;
        $scope.friendNameInput = toEdit.name;
        $scope.editMode = true;
        $scope.currIndex = id;
    }
    //Save the alteration
    $scope.doSaveTask = function () {
        $scope.myFriendList[$scope.currIndex] = ({ name: $scope.friendNameInput, firebase: $scope.friendFireInput });
        $scope.editMode = false;
        $scope.friendNameInput = "";
        $scope.friendFireInput = "";
    }
    //Birdie Killer
    $scope.doDeleteTask = function (id) {
        $scope.myFriendList.splice(id, 1);
    }
})